{% extends 'base.html' %}
{% load static %}

{% block css %}
<link rel="stylesheet" href="{% static 'mdeditor/css/editormd.min.css' %}">
<script src="{% static 'mdeditor/js/jquery.min.js' %}"></script>
<script src="{% static 'mdeditor/js/editormd.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/prettify.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/marked.min.js' %}"></script>
<script type="text/javascript">
  $(function(){
    editormd.markdownToHTML("markdown");
  })
</script>
<script>
    $(document).ready(function () {
        $('#test').click(function () {
            $.ajax({
                url:"{% url 'like' article.id %}",
                type:"post",
                dataType:"json",
                data:{csrfmiddlewaretoken:'{{ csrf_token }}'},
                success:function (result) {
                    if(result.success){
                      $('#test').val("赞一个("+ result.like_num + ")");
                      alert("点赞成功,感谢支持");
                    }else{
                      alert("请不要重复点赞");
                    }
                    
                }
            })
        })

    })
</script>
{% endblock %}

{% block main %}

<article> 
  <!--lbox begin-->
  <div class="lbox">
    <div class="content_box whitebg">
      <h2 class="htitle"><span class="con_nav">您现在的位置是：<a href="{% url 'blog:index' %}">首页</a>><a href="{% url 'blog:all' %}">全部文章</a></span>全部文章</h2>
      <h1 class="con_tilte">{{ article.title }}</h1>
      <p class="bloginfo"><i class="avatar"><img src="{{ article.author.avatar.url }}"></i><span>{{ article.author.nickname }}</span><span>{{ article.update_time }}</span><span>{% for tag in article.tag.all %}【<a href="{% url 'blog:tag' tag %}">{{ tag }}</a>】{% endfor %}</span><span>{{ article.view_count }}人已围观</span></p>
      <div class="con_text">
          <div id =markdown>
              <textarea style="display:none;"> {{article.content}} </textarea>
          </div>
            {% csrf_token %}
            <input class="diggit" id="test" type="submit" value="赞一个({{ like_num }})">
        <div class="nextinfo">
        {% if article.type == 0 %}
            {% if pre_article %}
                <p>上一篇：<a href="{% url 'blog:article' pre_article.pk %}">{{ pre_article.title }}</a></p>
            {% endif %}
            {% if next_article %}
                <p>下一篇：<a href="{% url 'blog:article' next_article.pk %}">{{ next_article.title }}</a></p>
            {% endif %}
        {% endif %}
        </div>
      </div>
    </div>
    {% if article.type == 0 %}
    <div class="whitebg">
      <h2 class="htitle">相关文章</h2>
      <ul class="otherlink">
          {% for article in relate_article %}
              <li><a href="{% url 'blog:article' article.id %}" title="{{ article.title }}">{{ article.title }}</a></li>
          {% endfor %}
      </ul>
    </div>
    {% endif %}

    <div class="whitebg gbook">
      <h2 class="htitle">文章评论</h2>
      <ul>
          {% for comment in comment_list %}
              <div class="fb"><ul><p class="fbtime"><span>{{ comment.create_time }}</span>{{ comment.user_name }}</p><p class="fbinfo">{{ comment.comment }}</p></ul></div>
          {% endfor %}

{#          <div class="fb"><ul><p class="fbtime"><span>2019-07-05 10:15:20</span> Lee</p><p class="fbinfo"></p>#}
{#              <div class="ecomment"><span class="ecommentauthor">网友 Lee 的原文：</span><p class="ecommenttext">顶顶顶顶</p></div>同意<p></p></ul></div>#}
{#            <script>#}
{#          function CheckPl(obj)#}
{#          {#}
{#          if(obj.saytext.value=="")#}
{#          {#}
{#          alert("您没什么话要说吗？");#}
{#          obj.saytext.focus();#}
{#          return false;#}
{#          }#}
{#          return true;#}
{#          }#}
{#          </script>#}
        <form action="{% url 'blog:comment' article.id %}" method="post" name="saypl" id="saypl" onsubmit="return CheckPl(document.saypl)">
          {% csrf_token %}
            <div id="plpost">
            <p class="saying"><span>共有{{ article.view_count }}条评论</span>来说两句吧...</p>
            <p class="yname"><span>用户名:</span>
              <input name="username" type="text" class="inputText" id="username" value="" size="16">
            </p>
        {#    <p class="yzm"><span>验证码:</span>#}
        {#      <input name="key" type="text" class="inputText" size="16">#}
        {#      <img src="/e/ShowKey/?v=pl" align="absmiddle" name="plKeyImg" id="plKeyImg" onclick="plKeyImg.src='/e/ShowKey/?v=pl&amp;t='+Math.random()" title="看不清楚,点击刷新"> </p>#}
{#            <input name="nomember" type="hidden" id="nomember" value="1" checked="checked">#}
            <textarea name="comment" rows="6" id="saytext"></textarea>
            <input name="imageField" type="submit" value="提交">
{#            <input name="id" type="hidden" id="id" value="23">#}
{#            <input name="classid" type="hidden" id="classid" value="5">#}
{#            <input name="enews" type="hidden" id="enews" value="AddPl">#}
{#            <input name="repid" type="hidden" id="repid" value="0">#}
{#            <input type="hidden" name="ecmsfrom" value="/xd/23.html">#}

          </div>
        </form>
      </ul>
    </div>
  </div>
  <!--lbox end-->
  <div class="rbox">
    {% include 'include/click_rank.html' %}
    {% include 'include/recommend.html' %}
    {% include 'include/tag.html' %}
{#    {% include 'include/may_like.html' %}#}
    {% include 'include/siteinfo.html' %}
  </div>
</article>
{% endblock %}